package com.qianji.controller;

import com.qianji.api.PrizeApps;
import com.qianji.pojo.PrizeDto;
import com.qianji.service.PrizeService;
import com.qianji.utils.Result;
import com.qianji.vo.PrizeAddVO;
import com.qianji.vo.PrizeUpdateVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 阳家桂 on 2021/3/12 15:44
 */
@RestController
@Slf4j
@RequestMapping("/prize/")
public class PrizeController {

    @Autowired
    private PrizeService prizeService;

    /**
     * 新增奖品
     * @param prizeAddVO
     * @return
     */
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public Result addPrize(@RequestBody PrizeAddVO prizeAddVO){
        Integer result = prizeService.addPrize(prizeAddVO);
        if (result>0){
            return Result.success("添加成功",200);
        }else {
            return  Result.failed("添加失败",400);
        }
    }

    /**
     * 删除奖品
     * @param prizeUpdateVO
     * @return
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public Result deletActiveById(@RequestBody PrizeUpdateVO prizeUpdateVO ){


        Integer result = prizeService.updatePrize(prizeUpdateVO);
        if (result>0){
            return Result.success("修改成功",200);
        }else {
            return  Result.failed("修改失败",400);
        }
    }

    /**
     * 查询奖品
     * @param prizeDto
     * @return
     */
    @RequestMapping(value = "find",method = RequestMethod.POST)
    public Result selectAll(@RequestBody PrizeDto prizeDto){


        return prizeService.selectAll(prizeDto);
    }
}
